class Solution:
    def findPeakElement(self, nums: list) -> int:
        i, max_i, min_i = len(nums) // 2, len(nums)-1, 0
        if nums[0] > nums[1]:
            return 0
        if nums[-1] > nums[-2]:
            return max_i
        while nums[i] < nums[i-1] or nums[i] < nums[i+1]:
            if nums[i] < nums[i-1]:
                max_i, i = i, (i + min_i) // 2 - i and (i + min_i) // 2 or i - 1
            else:
                min_i, i = i, (i + max_i) // 2 - i and (i + max_i) // 2 or i + 1
        return i


a = Solution()
print(a.findPeakElement([1, 2, 3, 1]))
print(a.findPeakElement([1, 2, 1, 3, 5, 6, 4]))
print(a.findPeakElement([1, 2, 1, 3, 5, 6, 4]))
